import entity.Book;

import java.io.*;

/**
 * ClassName: BookSample
 * Description:
 * date: 2021/10/15 11:21
 *
 * @author muci
 * @since JDK 1.8
 */
public class BookSample {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Book book = new Book();
        book.setId(0);
        book.setName("java");
        book.setAuthor("Herbert Schildt");
        book.setPrice("20");

        //序列化，并保存到 book.out 文件
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("D:\\ACompCode\\ASelf\\gitee\\muci-spring-security\\json-sample\\01-json\\src\\filePath\\book.out"));
        oos.writeObject(book);
        oos.flush();
        oos.close();
        //反序列化，读取book.out文件
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("D:\\ACompCode\\ASelf\\gitee\\muci-spring-security\\json-sample\\01-json\\src\\filePath\\book.out"));
        Book book1 = (Book) ois.readObject();
        System.out.println(book1.toString());

    }
}
